﻿///***************************************************************
/// 시  스  템 : Updms.Dvd
/// 단위시스템 : DVD
/// 계      층 : Presentation Layer
/// 프로그램명 : Dvd2011r
/// 파  일  명 : Dvd2011r.aspx.cs
/// 설      명 : DVD체크
///***************************************************************
/// 수정ID 일자       이름     내용
///---------------------------------------------------------------
/// CH001  2009-08-13 송시명   최초 작성
///***************************************************************
using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;

using SMFramework.Data;
using SMFramework.Utility;

using Base.Dac;
using Updms.Dvd.Exe;


namespace Updms.Dvd
{
	public partial class Dvd2011r : Updms.Common.BaseClass.PageBase
	{
		#region 전역영역

		//프로그램상수
		public static readonly string PID = "Dvd2011r";
		public static readonly string gs_path_info = "/updms/Dvd/" + PID + ".aspx";

		Global global = new Global();

		//검색
		protected string kw1 = "";	//스튜디오
		protected string kw2 = "";	//제목
		protected string kw3 = "";	//주연
		protected string kw4 = "0";	//평점
		protected string kw5 = "";	//내용
		protected string kw6 = "";	//외모
		protected string kw7 = "";	//복장
		protected string kw8 = "";	//캐릭터

		//메뉴 선택값
		protected string gs_sm = "";

		// 페이지모드
		private string gs_page_mode = "";

		#endregion

		#region Page_Load, OnPageLoad

		protected void Page_Load(object sender, EventArgs e)
		{
			SetInit();
			if (!Page.IsPostBack)
			{
				// 최초 화면 로딩시 처리해야 할 부분
				OnPageLoad();
			}
		}

		// OnPageLoad
		private void OnPageLoad()
		{
			SetLiterals(global.GetLabelInfoByPgmId(PID, LANG_SET));
		}

		#endregion

		#region InitializeComponent

		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);
			this.PreRender += new System.EventHandler(this.Page_PreRender);
		}

		#endregion

		#region SetInit

		//초기값설정
		private void SetInit()
		{
			lbl_search_flag.Text = "INIT";

			gs_sm = (Request.QueryString["sm"] == null || Request.QueryString["sm"].Trim().Length != 7)
					? global.GetDirDepth(PID) : Request.QueryString["sm"].ToString();
		}

		#endregion		

		#region 디테일 Method (CheckFile)

		//DeleteFile
		private void CheckFile(DataSet lo_ds)
		{
			string ls_sshot_path = FILE_PATH_DVD_SSHOT;
			string ls_movie_path = FILE_PATH_DVD_NOMO;
			string ls_title_db_real = "";
			string ls_title_sshot_db = "";
			string ls_sshot_db_real = "";

			//총 갯수
			lbl_total.Text = DataSetUtil.GetRowCount(lo_ds, "UPDMS_DVD_INFO").ToString();

			//제목(DB - 실제파일)
			for (int i = 0; i < DataSetUtil.GetRowCount(lo_ds, "UPDMS_DVD_INFO"); i++)
			{
				string ls_title = "";

				ls_title = DataSetUtil.GetFldStr(lo_ds, "UPDMS_DVD_INFO", i, "Title");

				if (ls_title.Length > 2)
				{
					if (FileUtil.IsFileExist(ls_movie_path + ls_title))
					{
						ls_title_db_real += "OK : " + ls_title + "<br/>";
					}
					else
					{
						ls_title_db_real += "<b class=\"unmatched\">UNMATCHED : " + ls_title + "</b><br/>";
					}
				}
			}

			lbl_title_db_real.Text = ls_title_db_real;

			//제목 - 스샷(DB)
			for (int i = 0; i < DataSetUtil.GetRowCount(lo_ds, "UPDMS_DVD_INFO"); i++)
			{
				string ls_title = "";
				string ls_attach_file = "";

				ls_title = DataSetUtil.GetFldStr(lo_ds, "UPDMS_DVD_INFO", i, "Title");
				ls_attach_file = DataSetUtil.GetFldStr(lo_ds, "UPDMS_DVD_INFO", i, "Attach_File1");

				if (ls_attach_file.Length > 2)
				{
					if (ls_title.Substring(0, ls_title.Length - 4) == ls_attach_file.Substring(0, ls_attach_file.Length - 4))

					{
						ls_title_sshot_db += "OK : " + ls_title + "<br/>";
					}
					else
					{
						ls_title_sshot_db += "<b class=\"unmatched\">UNMATCHED : " + ls_title + " / " + ls_attach_file + "</b><br/>";
					}
				}
			}

			lbl_title_sshot_db.Text = ls_title_sshot_db;

			//스샷 (DB - 실제파일)
			for (int i = 0; i < DataSetUtil.GetRowCount(lo_ds, "UPDMS_DVD_INFO"); i++)
			{
				string ls_attach_file = "";

				ls_attach_file = DataSetUtil.GetFldStr(lo_ds, "UPDMS_DVD_INFO", i, "Attach_File1");

				if (ls_attach_file.Length > 2)
				{
					if (FileUtil.IsFileExist(ls_sshot_path + ls_attach_file))
					{
						ls_sshot_db_real += "OK : " + ls_attach_file + "<br/>";
					}
					else
					{
						ls_sshot_db_real += "<b class=\"unmatched\">UNMATCHED : " + ls_attach_file + "</b><br/>";
					}
				}
			}

			lbl_sshot_db_real.Text = ls_sshot_db_real;
		}

		#endregion

		# region 리스트 (SelectProcess, SearchProcess)

		//조회
		private void SelectProcess()
		{
			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();

			//검색
			lo_dp.AddProperty("li_st_page", typeof(Int32), 0);
			lo_dp.AddProperty("li_ed_page", typeof(Int32), 100000);
			lo_dp.AddProperty("ls_studio", typeof(string), kw1);
			lo_dp.AddProperty("ls_title", typeof(string), kw2);
			lo_dp.AddProperty("ls_actress1", typeof(string), kw3);
			lo_dp.AddProperty("ls_rate", typeof(string), kw4);
			lo_dp.AddProperty("ls_contents", typeof(string), kw5);
			lo_dp.AddProperty("ls_look", typeof(string), kw6);
			lo_dp.AddProperty("ls_costume", typeof(string), kw7);
			lo_dp.AddProperty("ls_character", typeof(string), kw8);

			using (Dvd1012m_NT _Dvd1012m_NT = new Dvd1012m_NT())
			{
				lo_ds.Merge(_Dvd1012m_NT.SelectProcess(lo_dp));
			}

			CheckFile(lo_ds);
		}

		//검색
		private void SearchProcess()
		{
			gs_page_mode = "R";
			SelectProcess();
		}

		#endregion

		#region Page_PreRender, ChangePageMode

		// Page_PreRender
		private void Page_PreRender(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				using (AccessCheck access = new AccessCheck())
				{
					//접근권한 체크
					if (!access.CheckPgmAccessGrant(PID, USER_ID, ACCESS_LOG_INFO))
					{
						Response.Redirect(URL_NO_AUTHORITY_REDIRECT_BASE);	//사용자의 권한은 요청하신 페이지를 볼 수 없습니다
					}
				}
			}
			ChangePageMode();
		}

		// ChangePageMode
		private void ChangePageMode()
		{
			switch (gs_page_mode)
			{
				case "":	// 처음 페이지로드시
					table_detail_1.Visible = false;
					break;
				case "R":	// 검색버튼 클릭시
					table_detail_1.Visible = true;
					break;
			}
		}

		#endregion

		#region GridView이벤트

		//RowDataBound
		protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
		{
			if (e.Row.RowType == DataControlRowType.DataRow)
			{
				//마우스올렸을 때
				e.Row.Attributes.Add("onMouseOver", GRID_ONMOUSEOVER_COLOR);
				e.Row.Attributes.Add("onMouseOut", GRID_ONMOUSEOUT_COLOR);

				//번호
				e.Row.Cells[0].Text = (e.Row.RowIndex + 1).ToString();
			}
		}

		#endregion

		#region 버튼이벤트

		//검색
		protected void ibtn_search_Click(object sender, EventArgs e)
		{
			SearchProcess();
		}
		
		#endregion

	}
}
